package com.wanboedu.controller;

import com.wanboedu.dto.InvoiceDTO;
import com.wanboedu.entity.Invoice;
import com.wanboedu.result.PageResult;
import com.wanboedu.result.Result;
import com.wanboedu.service.InvoiceService;
import com.wanboedu.vo.DataViewTwoVO;
import com.wanboedu.vo.InvoiceVO;
import com.wanboedu.vo.SellerDataVO;
import com.wanboedu.vo.TypeDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/invoice")
@Slf4j
@Api("发票接口")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;


    @PostMapping("/entry")
    @ApiOperation("发票提交")
    public Result submit(@RequestBody InvoiceDTO invoiceDTO) {
        log.info("扫描发票: {}", invoiceDTO);
        invoiceService.submit(invoiceDTO);
        return Result.success();
    }

    @PostMapping("/list")
    @ApiOperation("发票列表")
    public Result getList(@RequestBody InvoiceDTO invoiceDTO) {
        log.info("获取发票列表", invoiceDTO);

        PageResult pageResult = invoiceService.getList(invoiceDTO);

        return Result.success(pageResult);
    }

    /**
     *全部数据
     * @return
     */
    @GetMapping("/data")
    @ApiOperation("获取全部数据")
    public Result allData(){
        log.info("获取全部数据");
        List<InvoiceVO> list = invoiceService.getAllList();
        return Result.success(list);
    }

    @GetMapping("/data2")
    @ApiOperation("获取每日数据")
    public Result DataTwo(){
        log.info("获取每日数据");
        List<DataViewTwoVO> dataViewTwoVOS = invoiceService.getdateValue();
        return Result.success(dataViewTwoVOS);
    }

    @GetMapping("/data3")
    @ApiOperation("获取类型数据")
    public Result TypeData(){
        log.info("获取类型数据");
       List<TypeDataVO> typeDataVOList = invoiceService.getTypeList();
       return Result.success(typeDataVOList);
    }

    @GetMapping("/data4")
    @ApiOperation("获取企业数据")
    public Result SellerData(){
        log.info("获取企业数据");
        List<SellerDataVO> sellerList = invoiceService.getSellerList();
        return Result.success(sellerList);
    }
    /**
     * 发票删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("发票删除：id:{}", id);
        invoiceService.delete(id);
        return Result.success();
    }
}
